/**
 * @file bsp.h
 * @brief 
 * @author  ()
 * @version 1.0
 * @date 2024-09-13
 * @defgroup bsp
 * @ingroup application
 * @copyright Copyright (C) 2019 Queclink Wireless Solutions (ShenZhen) Co., Ltd. All Rights Reserved.
 * 
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version <th>Author  <th>Description
 * <tr><td>2024-09-13 <td>1.0     <td>     <td>内容
 * </table>
 */
#ifndef __BSP_H
#define __BSP_H

#include <stdint.h>
#include <stdbool.h>
#include <time.h>


#ifdef __cplusplus
extern "C" {
#endif


/* [PROTOTYPE] uint32_t getms(void);
 * Please use this macro to get runtime(ns) in SDK */
#define getns       bsp_get_ns_since_boot

/* [PROTOTYPE] uint32_t getms(void);
 * Please use this macro to get runtime(ms) in SDK */
#define getms       bsp_get_ms_since_boot

/* [PROTOTYPE] uint32_t getsec(void);
 * Please use this macro to get runtime(second) in SDK */
#define getsec      bsp_get_seconds_since_boot

/* [PROTOTYPE] bool timeout_sec(uint32_t start_time, uint32_t timeout);
 * Please use this macro to calculate timeout for second in SDK */
#define timeout_sec(start_time, timeout) \
    bsp_seconds_is_timeout(start_time, timeout)

/* [PROTOTYPE] bool timeout_ms(uint32_t start_time, uint32_t timeout);
 * Please use this macro to calculate timeout for millisecond in SDK */
#define timeout_ms(start_time, timeout) \
    bsp_ms_is_timeout(start_time, timeout)


void bsp_init(void);
void bsp_init_after_wakeup(void);
void bsp_enter_lowpower(void);

/* boot time function list start */
/**
 * @brief 获取自启动后的总时长.包括STOP MODE时长
 * @return uint32_t 时长单位ms
 */
uint32_t bsp_get_ms_since_boot(void);

/**
 * @brief  获取自启动后的总时长.包括STOP MODE时长
 * @return uint64_t 时长单位ns
 */
uint64_t bsp_get_ns_since_boot(void);

/**
 * @brief 获取自启动后的总时长.包括STOP MODE时长
 * @return uint32_t 启动运行总时长,单位s
 */
uint32_t bsp_get_seconds_since_boot(void);

/**
 * @brief 判断当前时刻与start_time时刻相距是否超过了timeout ms
 * @param  start_time       开始时间
 * @param  timeout          超时时间,单位ms
 * @return true             计时器超时
 * @return false            计时器未超时
 */
bool bsp_ms_is_timeout(uint32_t start_time, uint32_t timeout);

/**
 * @brief 判断当前时刻与start_time时刻相距是否超过了timeout ns
 * @param  start_time       开始时间
 * @param  timeout          超时时间,单位ns
 * @return true             计时器超时
 * @return false            计时器未超时
 */
bool bsp_ns_is_timeout(uint64_t start_time, uint32_t timeout);

/**
 * @brief 判断当前时刻与start_time时刻相距是否超过了timeout s
 * @param  start_time       开始时间
 * @param  timeout          超时间隔
 * @return true             计时器超时
 * @return false            计时器未超时
 */
bool bsp_seconds_is_timeout(uint32_t start_time, uint32_t timeout);

/**
 * @brief 底层重启设备，应用调用tbox_system_reboot替代
 */
void bsp_reboot(void);

/**
 * @brief 关闭设备，休眠逻辑处理
 */
void bsp_poweroff(void);

/**
 * @brief 获取芯片唯一ID
 * @param  id               My Param doc
 * @param  str              My Param doc
 * @return int32_t 
 */
int32_t hdl_mcu_unique_devid_get(uint32_t id[3], char *str);


/**
 * @brief 判断是否处于DQA模式
 * @return true 
 * @return false 
 */
bool tbox_dqa_mode_get(void);


#ifdef __cplusplus
}
#endif


#endif // __BSP_H